package starter

import (
	"gitee.com/kristas/booting-go/framework"
	"gitee.com/kristas/booting-go/framework/core/bean"
	"gitee.com/kristas/booting-go/framework/core/statement/types"
	"gitee.com/kristas/booting-go/framework/web"
	"gitee.com/kristas/booting-go/framework/web/controller"
)

func init() {
	framework.Component(new(fsApiStarter))
}

type fsApiStarter struct {
	types.Component `name:"web:file_system_starter"`
	Container       web.Server       `wire:""`
	Controllers     []web.Controller `wire:""`
}

func (s *fsApiStarter) BeanStart() {
	for _, w := range s.Controllers {
		controller.HandleFsApi(w, s.Container.FsHandler)
	}
}

type FsApiProcessor struct {
	Container web.Server `wire:""`
}

func (f *FsApiProcessor) Order() int {
	return 255
}

func (f *FsApiProcessor) Filter(bean bean.Bean) bool {
	_, ok := bean.(web.Controller)
	return ok
}

func (f *FsApiProcessor) Do(bean bean.Bean) error {
	w := bean.(web.Controller)
	controller.HandleFsApi(w, f.Container.FsHandler)
	return nil
}

func (f *FsApiProcessor) Async() bool {
	return false
}
